﻿using System;

namespace Tree.ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            #region 初始化树
            BiTree<int> biTree = new BiTree<int>();
            Node<int> A = new Node<int>(4);
            Node<int> B = new Node<int>(5);
            Node<int> C = new Node<int>(7);
            Node<int> D = new Node<int>(1);
            Node<int> E = new Node<int>(2);
            Node<int> F = new Node<int>(6);
            Node<int> G = new Node<int>(10);
            biTree.Head = A;
            A.LChild = B;
            A.RChild = C;
            B.LChild = D;
            B.RChild = E;
            C.LChild = F;
            C.RChild = G;
            #endregion
            PreOrder(A);
            Console.WriteLine();
            InOrder(A);
            Console.WriteLine();
            PostOrder(A);
            Console.ReadLine();
        }
        /// <summary>
        /// 先序遍历
        /// </summary>
        /// <param name="root"></param>
        public static void PreOrder(Node<int> root)
        {
            if (root == null)
                return;
            Console.Write("{0} ", root.Data);
            PreOrder(root.LChild);
            PreOrder(root.RChild);
        }
        /// <summary>
        /// 中序遍历
        /// </summary>
        /// <param name="root"></param>
        public static void InOrder(Node<int> root)
        {
            if (root == null)
                return;
            InOrder(root.LChild);
            Console.Write("{0} ", root.Data);
            InOrder(root.RChild);
        }
        /// <summary>
        /// 后续遍历
        /// </summary>
        /// <param name="root"></param>
        public static void PostOrder(Node<int> root)
        {
            if (root == null)
                return;
            PostOrder(root.LChild);
            PostOrder(root.RChild);
            Console.Write("{0} ", root.Data);
        }
    }
}
